package ui;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Toolkit;

import javax.swing.ImageIcon;
import javax.swing.JLabel;

import td.Elf;
import td.Human;

/*
 * View class to represent Humans on the map.
 * */
public class HumanView extends EnemyView{

	public HumanView(Human human){
		super(human);
		//this.setLayout(new GridBagLayout());
		/*Sets the displayable image.*/
		image = Toolkit.getDefaultToolkit().getImage("Images/human.png");
		GridBagConstraints gridc = new GridBagConstraints();
		gridc.gridx = 0;
		gridc.gridy = 0;
		/*Sets up the hp display.*/
		gridc.anchor = GridBagConstraints.FIRST_LINE_END;
		hp = new JLabel(""+((Human) fieldElement).getHp());
		hp.setForeground(Color.cyan);
		add(hp,gridc);
		/*Puts up picture of the enemy*/
		gridc.anchor = GridBagConstraints.LAST_LINE_START;
		JLabel picLabel = new JLabel(new ImageIcon(image));
		add(picLabel,gridc);
		update();
	}
	
	/*
	 * Function to update the enemy's current hp display
	 * and put up status effect icons in the corner of
	 * the displayed picture, so the player knows
	 * if the unit is either slowed or set on fire.
	 * */
	@Override
	public void update() {
		hp.setText(""+((Human) fieldElement).getHp());
		if (((Human) fieldElement).onFire) {
			fire.setVisible(true);
		}else{
			fire.setVisible(false);
		}
		if (((Human) fieldElement).slowed) {
			slow.setVisible(true);
		}else{
			slow.setVisible(false);
		}
		//crit.setVisible(true);
	}

	public void paintComponent(Graphics g){
		super.paintComponents(g);
		Graphics2D g2D = (Graphics2D) g;
		g2D.drawImage(image, 0, 0, this);
	}
}
